import sqlite3

# 连接数据库（不存在会自动创建）
conn = sqlite3.connect('../langchain.db')
cursor = conn.cursor()

try:
    # 创建表
    cursor.execute('''CREATE TABLE IF NOT EXISTS users 
                      (id INTEGER PRIMARY KEY, name TEXT, age INTEGER)''')

    # 插入数据
    cursor.execute("INSERT INTO users (name, age) VALUES (?, ?)", ('Alice', 30))

    # 查询数据
    cursor.execute("SELECT * FROM users")
    print(cursor.fetchall())

    # 提交事务
    conn.commit()

except sqlite3.Error as e:
    print(f"数据库错误: {e}")

finally:
    # 关闭连接
    cursor.close()
    conn.close()